// pages/bargain/bargain.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        stare:0
        // stare:this.data.status
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      this.bargainlist()
    },

    //砍价列表
    bargainlist(){
      let that = this
      wx.request({
        url: 'http://fbj.wdmnm.vip/api/bargain',
        data: {},
        header: {'uid':wx.getStorageSync('uid')},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result)=>{
          console.log(result)
          that.setData({
            bargain:result.data.data
          })
        },
        fail: ()=>{},
        complete: ()=>{}
      });
    },
    //点击免费拿
    free(e){
     
      let product_id = e.currentTarget.dataset.id
      let that = this
      wx.request({
        url: 'http://fbj.wdmnm.vip/api/startBargian',
        data: {product_id:product_id},
        header: {'uid':wx.getStorageSync('uid')},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result)=>{
          console.log(result)
          that.setData({
            status:result.data.data
          })

          
        },
        fail: ()=>{},
        complete: ()=>{}
      });

      //倒计时
      wx.request({
        url: 'http://fbj.wdmnm.vip/api/getBargainTime',
        data: {product_id:product_id},
        header: {'uid':wx.getStorageSync('uid')},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result)=>{
          console.log(result)
          that.setData({
            times:result.data.data
          })

          
        },
        fail: ()=>{},
        complete: ()=>{}
      });

      //详情数据
      wx.request({
        url: 'http://fbj.wdmnm.vip/api/bargainDetail',
        data: {product_id:product_id},
        header: {'uid':wx.getStorageSync('uid')},
        method: 'GET',
        dataType: 'json',
        responseType: 'text',
        success: (result)=>{
          console.log(result)
          that.setData({
            detail:result.data.data
          })

          
        },
        fail: ()=>{},
        complete: ()=>{}
      });
    },

    continue(e){
      console.log(e)
      
      let bargain_id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: '/pages/bargainxiang/bargainxiang?bargain_id='+bargain_id,
      })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})